package at.guigu.controller;

import at.guigu.pojo.User;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 将Usercontroller放到Spring容器中
 * 测试：经配置后，SpringMVC自动将对象或集合转为JSON格式的字符串
 */
@Controller
@RequestMapping("/userFour")
public class UserControllerFour {
    /**
     * SpringMVC回写数据——直接返回字符串方式二：返回JSON格式响应字符串数据
     * @return
     * @throws JsonProcessingException
     */
    @ResponseBody
    @RequestMapping(value = "/quick3")
    public User save3() throws JsonProcessingException {
        User user = new User();
        user.setName("zhangsan");
        user.setAge(18);
        return user;
    }
}
